#define _XOPEN_SOURCE 500
#define _POSIX_C_SOURCE 200112L 

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
    struct stat sb;

	if(argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
  {
    write(STDOUT_FILENO,"Usage : ",8);
   	write(STDOUT_FILENO, argv[0],strlen(argv[0]));
   	write(STDOUT_FILENO," file",5);
    return (0);
  }
  
   if (argc < 2) 
   {
   		write(STDERR_FILENO,"Missing parameters\nUsage : ",28);
   		write(STDERR_FILENO, argv[0],strlen(argv[0]));
   		write(STDERR_FILENO," file",5);
    
   		exit(1);
    }

   if (stat(argv[1], &sb) == -1) 
   {
        perror(argv[0]);
        exit(2);
    }

   switch (sb.st_mode & S_IFMT) 
   {
    case S_IFBLK:  printf("block device\n");            break;
    case S_IFCHR:  printf("character device\n");        break;
    case S_IFDIR:  printf("directory\n");               break;
    case S_IFIFO:  printf("FIFO\n"); 			              break;
    case S_IFLNK:  printf("symlink\n");                 break;
    case S_IFREG:  printf("regular file: %lld\n", 
    	(long long) sb.st_size);													break;
    case S_IFSOCK: printf("socket\n");                  break;
    default:       printf("unknown?\n");                break;
    }
    
    return 0;
}
